<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        padding: 0;
        margin: 0;
      }
      html,
      body {
        height: 100%;
      }
      body {
        display: flex;
        flex-direction: column;
      }
      .p {
        flex: 1;
        display: flex;
        flex-direction: row;
      }
      .p > div {
        flex: 1;
      }
      .p > div:nth-child(2n + 1) {
        background-color: red;
      }
      .p:nth-child(2n) > div:nth-child(2n + 1) {
        background-color: blue;
      }
      .p:nth-child(2n) > div:nth-child(2n) {
        background-color: green;
      }
    </style>
  </head>
  <body>
    <div class="p">
      <div></div>
      <div></div>
      <div></div>
    </div>
    <div class="p">
      <div></div>
      <div></div>
      <div></div>
    </div>
    <div class="p">
      <div></div>
      <div></div>
      <div></div>
    </div>
  </body>
</html>
